package cn.idongjia.live.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;

/**
 * 直播权限表信息
 * Created by wuqiang on 16/3/31.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AuthLive extends AuthInfo {

    private static final long serialVersionUID = -7387771366044980985L;

    private Integer id;     //授权用户主键
    private Integer type;   //0-直播用户（id代表kp_user表主键），1-管理员（id代表kp_admin主键)
    private Integer atid;   //kp_auth_type表ID
    private Integer ztid;   //kp_zoo_type表ID

    public AuthLive() {
    }

    public AuthLive(Integer atid, Integer ztid) {
        this.atid = atid;
        this.ztid = ztid;
    }

    public AuthLive(Integer id, Integer type, Integer atid, Integer ztid) {
        this.id = id;
        this.type = type;
        this.atid = atid;
        this.ztid = ztid;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getAtid() {
        return atid;
    }

    public void setAtid(Integer atid) {
        this.atid = atid;
    }

    public Integer getZtid() {
        return ztid;
    }

    public void setZtid(Integer ztid) {
        this.ztid = ztid;
    }

    /**
     * 直播权限分配参数
     */
    public static class AuthLiveReq extends AuthInfo {

        private static final long serialVersionUID = -157477033242570391L;

        private LiveUser user;          //授权用户信息
        private List<Integer> atids;    //需要给用户授予:管理权限/直播权限/审核权限/权限分配权限
        private List<Integer> ztids;    //权限直播间类型

        public LiveUser getUser() {
            return user;
        }

        public void setUser(LiveUser user) {
            this.user = user;
        }

        public List<Integer> getAtids() {
            return atids;
        }

        public void setAtids(List<Integer> atids) {
            this.atids = atids;
        }

        public List<Integer> getZtids() {
            return ztids;
        }

        public void setZtids(List<Integer> ztids) {
            this.ztids = ztids;
        }
    }

    public static List<AuthLive> parseAuthLiveReq(AuthLiveReq req) {
        List<AuthLive> authLives = new ArrayList<>();
        for (Integer atid : req.getAtids()) {
            for (Integer ztid : req.getZtids()) {
                AuthLive authLive = new AuthLive();
                authLive.setId(req.getUser().getId());
                authLive.setType(req.getUser().getType());
                authLive.setAtid(atid);
                authLive.setZtid(ztid);
                authLives.add(authLive);
            }
        }
        return authLives;
    }

    /**
     * 对比权限是否匹配
     * 主要匹配直播间类型和操作权限两个属性
     * @param authLive
     * @return
     */
    public boolean authEqual(AuthLive authLive) {
        if (this.getAtid() == authLive.getAtid() && this.getZtid() == authLive.getZtid()) {
            return true;
        }
        return false;
    }

}
